package service.impl;

import common.consts.Consts;
import dao.AccountDao;
import dao.BalanceDao;
import domain.Account;
import domain.Balance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.BalanceService;
import service.ServiceResponse;

/**
 * Created by chen<chen@youjianghr.com> on 2015/7/17.
 *
 * @author chen<chen@youjianghr.com>
 */
@Service
public class BalanceServiceImpl extends ServiceBase implements BalanceService {

    @Autowired
    private AccountDao accountDao;

    @Autowired
    private BalanceDao balanceDao;

    /**
     * {@inheritDoc}
     */
    @Override
    public ServiceResponse getUserBalance(final long id) {
        Account account = accountDao.get(id);
        if (account == null) {
            return ServiceResponse.fail(Consts.i18nKey.INVALID_USER_ID);
        }

        Balance balance = balanceDao.get(id);
        if (balance == null) {
            return ServiceResponse.fail(Consts.i18nKey.BALANCE_EMPTY);
        }

        return ServiceResponse.success().with("balance", balance);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ServiceResponse blockUserBalanceStatus(long userId) {
        //TODO:uncompleted
        return null;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ServiceResponse ubBlockUserBalanceStatus(long userId) {
        //TODO:uncompleted
        return null;
    }

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }

    public void setBalanceDao(BalanceDao balanceDao) {
        this.balanceDao = balanceDao;
    }
}
